﻿using System;
using System.Collections.Generic;
using System.Linq;
using BML.Infrastructure.Platform;
using Service.Infrastructure.Interface;
using Service.Infrastructure.Model;
using Service.Infrastructure.Result;

namespace Service.Infrastructure.Implement
{
    public class UserLogService : BaseService, ILog
    {
        protected SystemicLoggerOp SystemicLoggerOp = new SystemicLoggerOp();
        public ServiceResult QueryLogs()
        {
            return Result(ResultType.OperateQueryIsSuccess, SystemicLoggerOp.QueryVisitLogs().Select(m => new UserLogModel
            {
                Id = m.Id,
                Browser = m.Browser,
                Ip = m.Ip,
                VisitPath = m.VisitPath,
                VisitTime = m.VisitTime.ToString(),
                OtherInfo = m.Others,
                HttpMethod = m.HttpMethod,
                Platform = m.Platform


            }).OrderByDescending(m => m.VisitTime).ToList());
        }

        public ServiceResult ProcessingLog(Guid id)
        {
            throw new NotImplementedException();
        }

        public ServiceResult Logging(Object info, string otherInfo)
        {
            var dict = (Dictionary<String, String>)info;

            SystemicLoggerOp.LoggingUserVisitInfo(
                dict["Browser"], dict["Ip"], dict["VisitPath"], dict["HttpMethod"], dict["Platform"],
                String.Format("IsAjax>>>{1} || PostParams:>>>{0} || {2}", dict["PostParams"], dict["IsAjax"], otherInfo));

            return Result(ResultType.OperateAddIsSuccess);
        }

    }
}
